package com.example.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zhangW
 * @create 2024-12-10-9:39
 */
@Component
public class MybatisConfig  implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createDate", Date.class, new Date()); // 插入时填充创建时间
        this.strictInsertFill(metaObject, "updateDate", Date.class, new Date()); // 插入时填充更新时间
        this.strictInsertFill(metaObject, "version", Integer.class, 0); // 插入时填充更新时间
        this.strictInsertFill(metaObject, "deleted", Integer.class, 0); // 插入时填充更新时间
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateDate", Date.class, new Date()); // 更新时填充更新时间
    }
}
